package com.whale.nangua.pumpkingobang.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.whale.nangua.pumpkingobang.bean.ReplayData;

import java.util.List;

public class ReplayAdapter extends BaseAdapter {
    private Context context;
    private List<ReplayData> replayDataList;

    public ReplayAdapter(Context context, List<ReplayData> replayDataList) {
        this.context = context;
        this.replayDataList = replayDataList;
    }

    @Override
    public int getCount() {
        return replayDataList.size();
    }

    @Override
    public Object getItem(int position) {
        return replayDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_2, parent, false);
            holder = new ViewHolder();
            holder.gameIdTextView = convertView.findViewById(android.R.id.text1);
            holder.endTimeTextView = convertView.findViewById(android.R.id.text2);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        ReplayData replayData = replayDataList.get(position);
        holder.gameIdTextView.setText("Game ID: " + replayData.getGameId());
        holder.endTimeTextView.setText("End Time: " + replayData.getEndTime());

        return convertView;
    }

    private static class ViewHolder {
        TextView gameIdTextView;
        TextView endTimeTextView;
    }
}
